﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms;

namespace Model.Test.Winforms
{
	public partial class Form1: Form
	{
        private ErrorProvider errorProvider;
        private ValidationProvider validationProvider;

		public Form1()
		{
			InitializeComponent();

            this.errorProvider = new System.Windows.Forms.ErrorProvider();
            this.errorProvider.ContainerControl = this;
           
            
            this.validationProvider = new ValidationProvider();
            this.validationProvider.Enabled = true;
            this.validationProvider.ErrorProvider = this.errorProvider;
            this.validationProvider.RulesetName = "RuleSetA";
            this.validationProvider.SourceTypeName = "Model.Customer, Model";
            this.validationProvider.SpecificationSource = Microsoft.Practices.EnterpriseLibrary.Validation.ValidationSpecificationSource.Attributes;


            this.validationProvider.SetPerformValidation(this.textBox1, true);
            this.validationProvider.SetSourcePropertyName(this.textBox1, "FirstName");
            this.validationProvider.SetPerformValidation(this.textBox2, true);
            this.validationProvider.SetSourcePropertyName(this.textBox2, "LastName");

            this.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange;
     

          
		}

        private void button1_Click(object sender, EventArgs e)
        {
           

            this.validationProvider.PerformValidation(this.textBox1);

            this.validationProvider.PerformValidation(this.textBox2);

            if (!validationProvider.IsValid)
            {
                MessageBox.Show("Errors !");
            }
            else
            {
                MessageBox.Show("no errors");
            }

        }


     

      
	}

 
}
